<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_users
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;
// Load the modal behavior script.
			JHtml::_('behavior.modal');

			// Build the script.
			$script = array();
			$script[] = '	function jInsertFieldValue(value, id) {';
			$script[] = '		var old_value = document.id(id).value;';
			$script[] = '		if (old_value != value) {';
			$script[] = '			var elem = document.id(id);';
			$script[] = '			elem.value = value;';
			$script[] = '			elem.fireEvent("change");';
			$script[] = '			if (typeof(elem.onchange) === "function") {';
			$script[] = '				elem.onchange();';
			$script[] = '			}';
			$script[] = '			jMediaRefreshPreview(id);';
			$script[] = '		}';
			$script[] = '	}';

			$script[] = '	function jMediaRefreshPreview(id) {';
			$script[] = '		var value = document.id(id).value;';
			$script[] = '		var img = document.id(id + "_preview");';
			$script[] = '		if (img) {';
			$script[] = '			if (value) {';
			$script[] = '				img.src = "' . JURI::root() . '" + value;';
			$script[] = '				document.id(id + "_preview_empty").setStyle("display", "none");';
			$script[] = '				document.id(id + "_preview_img").setStyle("display", "");';
			$script[] = '			} else { ';
			$script[] = '				img.src = ""';
			$script[] = '				document.id(id + "_preview_empty").setStyle("display", "");';
			$script[] = '				document.id(id + "_preview_img").setStyle("display", "none");';
			$script[] = '			} ';
			$script[] = '		} ';
			$script[] = '	}';

			$script[] = '	function jMediaRefreshPreviewTip(tip)';
			$script[] = '	{';
			$script[] = '		var img = tip.getElement("img.media-preview");';
			$script[] = '		tip.getElement("div.tip").setStyle("max-width", "none");';
			$script[] = '		var id = img.getProperty("id");';
			$script[] = '		id = id.substring(0, id.length - "_preview".length);';
			$script[] = '		jMediaRefreshPreview(id);';
			$script[] = '		tip.setStyle("display", "block");';
			$script[] = '	}';

			// Add the script to the document head.
			JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('behavior.modal');
JHtml::_('formbehavior.chosen', 'select');
$id 	 = $_GET["id"];
if(isset($id)&&$id!=0 ){
		$db	 = &JFactory::getDBO();
		$user   = & JFactory::getUser();
	    $uid  	= $user->get('id');
		$query  = $db->getQuery(true);
		// Select all records from the user profile table where key begins with "custom.".
		// Order it by the ordering field.
		$query->select('*');
		$query->from('#__gallery');
		$query->where('id='.$id);
		// Reset the query using our newly populated query object.
		$db->setQuery($query);
		$results = $db->loadObjectList();
		foreach($results as $row){
			$name 		 = $row -> name;
			$image 	    = $row -> images;
			$status  	   = $row -> status;
			$detail       = $row -> detail;
		}
}
?>

<form action="<?php echo JRoute::_('index.php?option=com_profiles&task=postGallery');?>" method="post" name="adminForm" id="adminForm">
    <input type="hidden" name="id" value="<?php echo @$row -> id;?>" />
	<div>
    	<span><strong>Name: </strong></span>&nbsp;&nbsp;
        <span><input name="name" type="text" value="<?php echo @$name;?>" />
    </div>
    <div class="control-group">
		<div class="control-label">
			<label id="jform_params_imageurl-lbl" for="jform_params_imageurl" class="hasTip" title=""><strong>Image</strong></label>								
        </div>
        
	  <div class="controls">
			<div class="input-prepend input-append">
				<div class="media-preview add-on">
					<span class="hasTipPreview" title=""><i class="icon-eye"></i></span>
			    </div>
				<input type="text" class="input-small" name="jform[params][imageurl]" id="jform_params_imageurl" value="" readonly="readonly" size="40">                
                <a class="modal btn" title="Select" href="index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=com_banners&amp;author=&amp;fieldid=jform_params_imageurl&amp;folder=" rel="{handler: 'iframe', size: {x: 800, y: 500}}">
                Select</a><a class="btn hasTooltip" href="#" onclick="
                jInsertFieldValue('', 'jform_params_imageurl');
                return false;
                " data-original-title="Clear">
                <i class="icon-remove"></i></a>
        </div>								
        </div>
		<?php if($image!=""){
                $images = explode("/", $image); 
                //print_r($images);
        ?>
            <span><img src="../images/background/<?php echo $uid;?>/gallery/<?php echo $images[2];?>" width="100" height="50" /></span>
        <?php } ?>
	</div>
    <p>&nbsp;</p>
    <div>
    	<span><strong>Status: </strong></span>&nbsp;&nbsp;
        <span><input name="status" type="radio" value="1" <?php if($status==1) echo "checked='checked'"; ?> /></span><span> Yes </span>&nbsp;&nbsp;
        <span><input name="status" type="radio" value="0" <?php if($status==0) echo "checked='checked'"; ?> /> No </span>
    </div>
    <p>&nbsp;</p>
    <?php
		$editor =& JFactory::getEditor();
		$params = array( 'smilies'=> '0' ,
						 'style'  => '1' ,  
						 'layer'  => '0' , 
						 'table'  => '0' ,
						 'clear_entities'=>'0'
						 );
		echo $editor->display( 'detail', $detail, '100%', '300', '20', '20', false, $params );
    ?>
    <input type="submit" value="Save" name="btnSave" />
</form>
